/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.xuexiang.xuidemo.slice.imageview;

import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Component;
import ohos.agp.components.Image;

import com.isotne.glidelibrary.utils.OhosGlide;
import com.xuexiang.xuidemo.ResourceTable;

/**
 * 图片加载策略
 *
 * @since 2021-04-08
 */
public class ImageLoadStrategySlice extends AbilitySlice {
    private Image mNetImage, mNetImageOther,mImageBack;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_image_load);
        initView();
        initData();
    }

    private void initView() {
        mImageBack = (Image) findComponentById(ResourceTable.Id_image_back);
        mImageBack.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                onBackPressed();
            }
        });
        mNetImage = (Image) findComponentById(ResourceTable.Id_net_image);
        mNetImageOther = (Image) findComponentById(ResourceTable.Id_net_image_other);
    }

    private void initData() {
            OhosGlide.with(this).load("https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fwww.wallcoo"
                + ".com%2Fnature%2Fda_ps_landscape_01%2Fwallpapers%2F1280x1024%2F%5Bwallcoo_com%5D_1"
                + ".jpg&refer=http%3A%2F%2Fwww.wallcoo.com&app=2002&size=f9999,"
                + "10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1614218186&t=37efae92a69da2fe7685a2813ad36b50")
                .def(ResourceTable.Media_xui_ic_default_img).into(mNetImage);
            OhosGlide.with(this).load("https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fwww.wallcoo"
                + ".com%2Fnature%2Fda_ps_landscape_01%2Fwallpapers%2F1280x1024%2F%5Bwallcoo_com%5D_1"
                + ".jpg&refer=http%3A%2F%2Fwww.wallcoo.com&app=2002&size=f9999,"
                + "10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1614218186&t=37efae92a69da2fe7685a2813ad36b50")
                .def(ResourceTable.Media_xui_ic_default_img).into(mNetImageOther);
    }
}
